
#ifndef IMG_H
#define IMG_H

#include <SDL/SDL.h>
#include "gl.h"

#include <string>
#include <vector>
using namespace std;

int init_img();
void kill_img();

class Texture {
	private:
		void _init();
		unsigned long alloc_ref;
		GLuint tex;
	protected:
		GLfloat tmaxW, tmaxH;
		// Width of the source image in pixels
		unsigned long texW, texH;
		bool has_tex;
		bool bind();
	public:
		Texture();
		Texture(const char*);
		Texture(SDL_Surface*);
		~Texture();
		virtual bool fromFile(const char*);
		virtual SDL_Surface* fromSDLSurface(SDL_Surface*);
	friend class Scrolling;
};

typedef enum aspect {
	TO_WIDTH,
	TO_HEIGHT
} Aspect;

class Renderable {
	public:
		virtual bool render() {
			return FALSE;
		};
};

class Image: public Texture, public Renderable {
	private:
		void configTex();
		void _init();
	protected:
		GLfloat tex_rect[4][2];
		GLfloat corner[4][2];
		GLfloat imgW, imgH, imgX, imgY;
	public:
		/* Render the image centered */
		virtual bool render();
		bool position(GLfloat x, GLfloat y);
		Image();
		Image(const char*);
		Image(SDL_Surface*);
		SDL_Surface* fromSDLSurface(SDL_Surface*);

		bool scale(GLfloat w, GLfloat h);
};

class Scrolling: public Image {
	private:
		void _init();
		GLfloat c_scrollX, c_scrollY;
		void renderRow();
	public:
		Scrolling();
		Scrolling(const char*);
		Scrolling(SDL_Surface*);
		GLfloat scrollX, scrollY;
		bool render();
};

#endif
/* vim:set ts=2 sts=2 sw=2 noexpandtab: */
